// pages/zuowen/zuowen.js
const db = wx.cloud.database();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    gradeList:[
      {
        "name": "一年级",
        "id": 11
      },
      {
        "name": "二年级",
        "id": 12
      },
      {
        "name": "三年级",
        "id": 13
      },
      {
        "name": "四年级",
        "id": 14
      },
      {
        "name": "五年级",
        "id": 15
      },
      
      {
        "name": "六年级",
        "id": 16
      },
      {
        "name": "小升初",
        "id": 17
      },
      {
        "name": "初一",
        "id": 21
      },
      {
        "name": "初二",
        "id": 22
      },
      {
        "name": "初三",
        "id": 23
      },
      {
        "name": "中考",
        "id": 24
      },
      
     
      {
        "name": "高一",
        "id": 31
      },
     
      {
        "name": "高二",
        "id": 32
      },
      
      {
        "name": "高三",
        "id": 33
      },
      {
        "name": "高考",
        "id": 34
      },
    ],
    typeList:[
      {
        "name": "看图",
        "id": 34
      },
      {
        "name": "游记",
        "id": 31
      },
      {
        "name": "叙事",
        "id": 12
      },
      
      {
        "name": "状物",
        "id": 14
      },
      {
        "name": "诗歌",
        "id": 29
      },
      {
        "name": "写人",
        "id": 11
      },
      {
        "name": "写景",
        "id": 13
      },
      {
        "name": "童话",
        "id": 25
      },
      {
        "name": "散文",
        "id": 26
      },
      {
        "name": "议论文",
        "id": 15
      },
      {
        "name": "读后感",
        "id": 21
      },
      {
        "name": "日记",
        "id": 18
      },
      {
        "name": "寓言",
        "id": 28
      },
      {
        "name": "说明文",
        "id": 16
      },
      {
        "name": "读书笔记",
        "id": 32
      },
      {
        "name": "话题",
        "id": 36
      },
      {
        "name": "想象",
        "id": 35
      },
      {
        "name": "演讲稿",
        "id": 22
      },
      {
        "name": "应用文",
        "id": 50
      },
      {
        "name": "书信",
        "id": 17
      },
      {
        "name": "小说",
        "id": 24
      },
      {
        "name": "其他",
        "id": 40
      },
    ],
    wordList:[
      {
        "name": "100字",
        "id": 2
      },
      {
        "name": "200字",
        "id": 4
      },
      {
        "name": "300字",
        "id": 6
      },
      {
        "name": "400字",
        "id": 8
      },
      {
        "name": "500字",
        "id": 10
      },
      {
        "name": "600字",
        "id": 12
      },
      {
        "name": "700字",
        "id": 14
      },
      {
        "name": "800字",
        "id": 16
      },
      {
        "name": "900字",
        "id": 17
      },
      {
        "name": "1000字",
        "id": 18
      },
      {
        "name": "1200字",
        "id": 19
      },
      {
        "name": "1200字以上",
        "id": 20
      },
      
      
    ],
    levelList:[
      {
        "id": 4,
        "name": "优"
      },
      {
        "id": 3,
        "name": "良"
      },
      {
        "id": 2,
        "name": "中"
      },
      {
        "id": 1,
        "name": "差"
      }
    ],
    gradeId:0,
    typeId:0,
    wordId:0,
    leaveId:0,
    page:1,
  },
  getId(e){
    let slectObj  = e.currentTarget.dataset
    let key = Object.keys(slectObj);
    switch(key[0]){
      case 'gradeid':
        this.setData({
          gradeId: parseInt(slectObj.gradeid)
        })
        break;
      case 'typeid':
        this.setData({
          typeId: parseInt(slectObj.typeid)
        })
        break;
      case 'wordid':
        this.setData({
          wordId: parseInt(slectObj.wordid)
        })
        break;
      case 'leaveid':
        this.setData({
          leaveId: parseInt(slectObj.leaveid)
        })
        break;
    }
  },
  search(){
    wx.navigateTo({
      url: `/pages/booklist/booklist?gradeId=${this.data.gradeId}&typeId=${this.data.typeId}&wordId=${this.data.wordId}&level=${this.data.leaveId}&page=${this.data.page}`,
    })
  },
  searchBook : function (id) {
    return db.collection('bookdetail').where({
      id: id
    }).get().then(res => {
      console.log(res.data,'----')
      return res.data;
    }).catch(err => {
      return err
      console.log(err)
    })
  },
  add: function (id) {
    return db.collection('test').add({
      data:{
        _id:0,
        name:'哈UN尴尬u',
        price:'919',
        category:'asd '
      }
    }).then(res => {
      console.log(res, '-11---')
      return res;
    }).catch(err => {
      return err
      console.log(err)
    })
  },
  ss(){
    var json ={
      gradeId: '0',
      level: '0',
      page: '1',
      typeId: '0',
    }
    let str='';

    Object.keys(json).forEach(key=>{
      str += `&${key}=${json[key]}`;
    })
    return str.slice(1);
    
    console.log(str)

  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(this.ss());
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})